﻿using Blog190311.Models;
using Blog190311.Models.DAL;
using Blog190311.Models.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Blog190311.Controllers
{
    public class ArticleController : Controller
    {
        // GET: Article
        /// <summary>
        /// 我的日记视图
        /// </summary>
        /// <param name="Tags"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public ActionResult Index(string page, string limit, string con, string Tags, string Type)
        {
            if (string.IsNullOrWhiteSpace(page))
            {
                page = "1";
            }
            if (string.IsNullOrWhiteSpace(limit))
            {
                limit = "10";
            }
            //创建一个articleService对象
            ArticleService articleService = new ArticleService();
            //调用service层的相应方法，获取到日记信息
            List<Article> list = articleService.GetArticleByPage(Convert .ToInt32(page), Convert.ToInt32(limit), con, Tags, Type);
            //返回日记信息
            ViewBag.total = articleService.GetCount(con);
            ViewBag.page = page;
            ViewBag.limit = limit;
            return View(list);
        }

        /// <summary>
        /// 日记详情视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Detail(int id,string CreateTime)
        {
            //创建一个articleService对象
            ArticleService articleService = new ArticleService();
            //调用service层的相应方法，获取到日记详情
            Article article = articleService.GetArticles(id);
            ViewBag.prev = articleService.GetArticleByIdPrev(id);
            ViewBag.next = articleService.GetArticleByIdNext(id);
            //返回日记详情
            return View(article);
        }
    }
}